package com.ximi.ximimall.goods.service;

import cn.hutool.core.date.DateTime;
import com.ximi.ximimall.mapper.LitemallGoodsProductMapper;
import com.ximi.ximimall.model.LitemallGoodsProduct;
import com.ximi.ximimall.model.LitemallGoodsProductExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class LitemallGoodsProductService {
    @Resource
    private LitemallGoodsProductMapper litemallGoodsProductMapper;


    public List<LitemallGoodsProduct> queryByGid(Integer gid) {
        LitemallGoodsProductExample example = new LitemallGoodsProductExample();
        example.or().andGoodsIdEqualTo(gid).andDeletedEqualTo(false);
        return litemallGoodsProductMapper.selectByExample(example);
    }

    public LitemallGoodsProduct findById(Integer id) {
        return litemallGoodsProductMapper.selectByPrimaryKey(id);
    }



    public void add(LitemallGoodsProduct goodsProduct) {
        goodsProduct.setAddTime(DateTime.now());
        goodsProduct.setUpdateTime(DateTime.now());
        litemallGoodsProductMapper.insertSelective(goodsProduct);
    }

    public int count() {
        LitemallGoodsProductExample example = new LitemallGoodsProductExample();
        example.or().andDeletedEqualTo(false);
        return (int) litemallGoodsProductMapper.countByExample(example);
    }


    public void updateById(LitemallGoodsProduct product) {
        product.setUpdateTime(DateTime.now());
        litemallGoodsProductMapper.updateByPrimaryKeySelective(product);
    }
}